package com.dq.domain.sys.user.user;

import com.dq.vo.baseVo.VO;
import com.dq.domain.sys.menu.SysMenu;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

import static com.dq.vo.baseVo.VO.inCaseNull;

/**
 * @author liuhui
 * @date 2019/11/20 0020 10:26:05
 * @description 技师实体
 */
@Data
@Entity
@ApiModel("员工用户实体")
public class StaffUser extends SysUser implements VO.ToVO{

    @ApiModelProperty("身份证号码")
    protected String idCardNo;

    @ApiModelProperty("身份证正面图")
    protected String idCardFrontImage;

    @ApiModelProperty("身份证背面图")
    protected String idCardBackImage;


    @ApiModelProperty("工作经历")
    protected String workingInfo;
    @ApiModelProperty("家庭情况描述")
    protected String familyInformation;
    @ApiModelProperty("基本工资")
    protected BigDecimal baseSalary;

    @ApiModelProperty("门店荣誉墙员工描述")
    protected String honorWallInfomation;

    @ApiModelProperty("门店荣誉墙员工照片")
    protected String honorWallStaffImage;
    @Transient
    @ApiModelProperty("员工评分")
    protected BigDecimal average;
    @ApiModelProperty("员工标签")
    protected String tag;

    @Data
    @ApiModel(value = "员工用户视图")
    public static class Vo implements VO {
        @ApiModelProperty(value = "用户id")
        private Long id;
        @ApiModelProperty(value = "用户编号")
        private String cardNo;
        @ApiModelProperty(value = "用户登陆名")
        private String username;
        @ApiModelProperty(value = "用户姓名")
        private String userRealcName;
        @ApiModelProperty("身份证号码")
        protected String idCardNo;
        @ApiModelProperty("员工离职时间")
        protected String leaveTime;
        @ApiModelProperty("入职时间")
        protected String entryTime;
        @ApiModelProperty(value = "状态")
        private Status status;
        @ApiModelProperty("账号状态")
        private String statusCn;
        @ApiModelProperty("账号状态")
        protected String statusEn;
        @ApiModelProperty("员工状态")
        private String staffStatusCn;
        @ApiModelProperty("员工状态")
        private String staffStatusEn;
        @ApiModelProperty(value = "用户岗位")
        private String orgPositionName;
        @ApiModelProperty("岗位id")
        private Long orgPositionId;
        @ApiModelProperty(value = "手机号")
        private String mobile;
        @ApiModelProperty("用户生日")
        protected String brithday;
        @ApiModelProperty(value = "邮箱")
        private String email;
        @ApiModelProperty("微信号")
        protected String wxNumber;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "头像")
        private String headImg;
        @ApiModelProperty(value = "邀请人微信手机号")
        private String inviteUserMobile;
        @ApiModelProperty("token")
        private String token;
        @ApiModelProperty("绑定门店")
        private Long orgId;
        @ApiModelProperty("门店名")
        private String orgName;
        @ApiModelProperty(value = "组织部门/门店")
        private Long sectionId;
        @ApiModelProperty(value = "组织部门/门店")
        private String sectionSimpleName;

        @ApiModelProperty("省份")
        protected String province;
        @ApiModelProperty("城市")
        protected String city;
        @ApiModelProperty("区")
        protected String district;

        @ApiModelProperty("工作经历")
        protected String workingInfo;
        @ApiModelProperty("家庭情况描述")
        protected String familyInformation;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty("最后修改时间")
        private String lastModifyTime;
        @ApiModelProperty("身份证正面图")
        protected String idCardFrontImage;

        @ApiModelProperty("身份证背面图")
        protected String idCardBackImage;

        @ApiModelProperty(value = "角色code列表")
        private Set<String> roleCodes;
        @ApiModelProperty("菜单id列表")
        private List<SysMenu.Vo> menuList;
        @ApiModelProperty("按钮id列表")
        private Set<SysMenu.Vo> buttonList;
        protected String tag;

    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.orgPositionName = this.getOrgPosition() == null ? "" : this.getOrgPosition().getPostName();
        vo.orgPositionId = this.getOrgPosition() == null ? null : this.getOrgPosition().getId();
        vo.cardNo = this.cardNo;
        vo.idCardNo = fmt(this.getIdCardNo());
        vo.entryTime = fmt(this.getEntryTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.brithday = fmt(this.getBrithday(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.userRealcName = this.getUserRealcName();
        vo.username = this.username;
        vo.email = this.email;
        vo.mobile = this.mobile;
        vo.status = this.status != null ?this.status:null;
        vo.statusEn = fmt(this.getStatus().toString());
        vo.statusCn = fmt(this.getStatus().name);
        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.headImg = this.headImg;
        vo.orgId = this.getSection().getId();
        vo.orgName = this.getSection().getSimpleName();
        vo.sectionId = this.getSection() == null ? null : this.getSection().getId();
        vo.sectionSimpleName = this.getSection() == null ? "" : this.getSection().getSimpleName();

        vo.province = fmt(this.getProvince());
        vo.city = fmt(this.getCity());
        vo.district = fmt(this.getDistrict());


        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.wxNumber = this.getWxNumber();
        vo.workingInfo = fmt(this.getWorkingInfo());
        vo.familyInformation = fmt(this.getFamilyInformation());
        vo.idCardFrontImage = this.getIdCardFrontImage();
        vo.idCardBackImage = this.getIdCardBackImage();
        vo.tag = this.getTag();
        return vo;
    }

    @Data
    @ApiModel(value = "用户档案列表视图")
    public static class StaffUserFileListVo{
        @ApiModelProperty("id")
        protected Long id;

        @ApiModelProperty("用户头像")
        protected String imageUrl;

        @ApiModelProperty("真实中文姓名")
        protected String realCName;

        @ApiModelProperty("手机号")
        protected String phone;
    }

    @Data
    @ApiModel("员工档案详情视图")
    public static class StaffUserDetailVo{
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("岗位id")
        protected Long positionId;
        @ApiModelProperty("岗位名称")
        protected String positionName;
        @ApiModelProperty("真实姓名")
        protected String userRealName;
        @ApiModelProperty("工号")
        protected String jobNumber;
        @ApiModelProperty("手机号")
        protected String phone;
        @ApiModelProperty("微信号")
        protected String wxNumber;
        @ApiModelProperty("身份证号码")
        protected String idCardNo;
        @ApiModelProperty("入职时间")
        protected String entryTime;
        @ApiModelProperty("家庭情况")
        protected String familyInformation;
        @ApiModelProperty("工作情况")
        protected String workingInfo;
        @ApiModelProperty("基本工资")
        protected BigDecimal baseSalary;
        @ApiModelProperty("头像")
        protected String headImg;
        @ApiModelProperty("员工评分")
        protected BigDecimal average;
    }

    @Data
    @ApiModel("预约技师列表视图")
    public static class StaffUserVo{
        protected Long id;
        protected String userRealCName;
        @ApiModelProperty("门店荣誉墙员工照片")
        protected String honorWallStaffImage;
        protected String phone;
    }

    public StaffUserDetailVo toStaffUserDetailVo(){
        StaffUser.StaffUserDetailVo staffUserDetailVo = new StaffUser.StaffUserDetailVo();
        staffUserDetailVo.id = this.getId();
        staffUserDetailVo.userRealName = this.userRealcName;
        staffUserDetailVo.positionId = this.getOrgPosition() !=null ?fmt(this.getOrgPosition().getId()):null;
        staffUserDetailVo.positionName =this.getOrgPosition() !=null ? fmt(this.getOrgPosition().getPostName()):null;
        staffUserDetailVo.jobNumber = this.getCardNo() != null? fmt(this.getCardNo()):"";
        staffUserDetailVo.phone =this.getUsername()!= null? fmt(this.getUsername()):"";
        staffUserDetailVo.wxNumber = this.getWxNumber() != null?fmt(this.getWxNumber()):"";
        staffUserDetailVo.idCardNo = this.getIdCardNo()!= null?fmt(this.getIdCardNo()):"";
        staffUserDetailVo.entryTime =this.getEntryTime()!=null? fmt(this.getEntryTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS):"";
        staffUserDetailVo.familyInformation =this.getFamilyInformation()!= null? fmt(this.getFamilyInformation()):"";
        staffUserDetailVo.workingInfo = this.getWorkingInfo()!= null?fmt(this.getWorkingInfo()):"";
        staffUserDetailVo.baseSalary =this.getBaseSalary()!= null? fmt(this.getBaseSalary()):BigDecimal.ZERO;
        staffUserDetailVo.headImg = this.getHeadImg() != null?fmt(this.getHeadImg()):"";
        staffUserDetailVo.average = this.getAverage() != null ?fmt(this.getAverage()) :BigDecimal.ZERO;
        return staffUserDetailVo;
    }

    public StaffUserFileListVo toStaffUserFileListVo(){
        StaffUser.StaffUserFileListVo staffUserFileListVo = new StaffUser.StaffUserFileListVo();
        staffUserFileListVo.id = this.getId();
        staffUserFileListVo.imageUrl = fmt(this.getHeadImg());
        staffUserFileListVo.realCName = fmt(this.getUserRealcName());
        staffUserFileListVo.phone =fmt(this.getUsername());
        return staffUserFileListVo;
    }

    public StaffUserVo toStaffUserVo(){
        StaffUserVo staffUserVo = new StaffUserVo();
        staffUserVo.id = this.id;
        staffUserVo.userRealCName = this.userRealcName;
        staffUserVo.honorWallStaffImage = this.honorWallStaffImage;
        staffUserVo.phone = this.username;
        return staffUserVo;
    }

    @Data
    @ApiModel("技师用户视图")
    public static class StaffUserLoginVo{
        @ApiModelProperty(value = "用户id")
        private Long userId;
        @ApiModelProperty("token")
        private String token;
        @ApiModelProperty("所属门店")
        private Org.Vo ofOrg;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty("岗位id")
        protected Long positionId;
        @ApiModelProperty("岗位名称")
        protected String positionName;
        @ApiModelProperty("工号")
        protected String jobNumber;
        @ApiModelProperty("手机号")
        protected String phone;
        @ApiModelProperty("微信号")
        protected String wxNumber;
        @ApiModelProperty("身份证号码")
        protected String idCardNo;
        @ApiModelProperty("入职时间")
        protected String entryTime;
        @ApiModelProperty("家庭情况")
        protected String familyInformation;
        @ApiModelProperty("工作情况")
        protected String workingInfo;
    }

    public StaffUserLoginVo toStaffUserLoginVo(){
        StaffUserLoginVo vo = new StaffUserLoginVo();
        vo.userId = this.getId();
        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.ofOrg = (Org.Vo) inCaseNull(this.getSection(), false);
        vo.positionName =this.getOrgPosition()!= null ? fmt(this.getOrgPosition().getPostName()):"";
        vo.jobNumber = fmt(this.getCardNo());
        vo.phone = fmt(this.getUsername());
        vo.wxNumber = fmt(this.getWxNumber());
        vo.idCardNo = fmt(this.getIdCardNo());
        vo.entryTime = fmt(this.getEntryTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.familyInformation = fmt(this.getFamilyInformation());
        vo.workingInfo = fmt(this.getWorkingInfo());
        return vo;
    }

    @Data
    @ApiModel("技师我的")
    public static class StaffUserInfo{
        @ApiModelProperty("用户真实姓名")
        protected String userRealCName;
        @ApiModelProperty("头像")
        protected String headImg;
        @ApiModelProperty("员工岗位")
        protected String orgPosition;
        @ApiModelProperty("评分人数")
        protected Long scoreNum;
        @ApiModelProperty("评分平均分")
        protected BigDecimal average;
        @ApiModelProperty("展示姓名")
        protected String localNickName;
        @ApiModelProperty("手机号")
        protected String mobile;
    }

    public StaffUserInfo toStaffUserInfo(Long scoreNum,BigDecimal average){
        StaffUserInfo vo = new StaffUserInfo();
        vo.userRealCName = fmt(this.userRealcName);
        vo.headImg = fmt(this.headImg);
        vo.orgPosition = this.orgPosition.getPostName();
        vo.scoreNum = scoreNum;
        vo.average = average;
        vo.localNickName = fmt(this.localNickName);
        vo.mobile = fmt(this.username);
        return vo;
    }

    @ApiModel("用户选择框")
    @Data
    public static class SimpleWxUser{
        @ApiModelProperty("用户id")
        protected Long wxUserId;
        @ApiModelProperty("会员卡号/工号")
        protected String cardNo;
        @ApiModelProperty("用户真实姓名")
        protected String userRealCName;
        @ApiModelProperty("手机号")
        protected String username;
    }

    public SimpleWxUser toSimpleWxUser() {
        SimpleWxUser vo = new SimpleWxUser();
        vo.wxUserId = this.id;
        vo.cardNo = this.cardNo;
        vo.username = this.username;
        vo.userRealCName = this.userRealcName;
        return vo;
    }

    @ApiModel("pc基本工资")
    @Data
    public static class PcVo{
        public Long id;
        @ApiModelProperty("基本工资")
        protected BigDecimal payPrice;
        protected Long orgId;
        protected String orgName;
        protected Long staffUserId;
        protected String staffUserNo;
        protected String userRealName;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }

    public PcVo toPcVo(){
        PcVo vo = new PcVo();
        vo.id = this.id;
        vo.payPrice = this.getBaseSalary() != null ? this.getBaseSalary():BigDecimal.ZERO;
        vo.orgId = this.getSection().getId();
        vo.orgName =this.getSection().getSimpleName();
        vo.staffUserId = this.getId();
        vo.staffUserNo = this.getCardNo();
        vo.userRealName = this.getUserRealcName();


        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();
        return vo;
    }

}
